/*class Node{
    public int val;
    public Node left;
    public Node right;
    public Node(int val){
        this.val=val;
    }
}*/
/*
public class BInarysearchTree {
    public static Node root;
    public Node select(int val){
        Node cur=root;
        while(cur!=null){
            if(cur.val<val){
                cur=cur.right;
            }else if(cur.val==val){
                return cur;
            }else{
                cur=cur.left;
            }
        }
        return null;
    }

    public boolean insert(int val){
        if(root==null){
            root=new Node(val);
            return true;
        }
        Node parent=null;
        Node cur=root;
        while(cur!=null){
            if(cur.val<val){
                parent=cur;
                cur=cur.right;
            }else if(cur.val==val){
                return false;
            }else{
                parent=cur;
                cur=cur.left;
            }
        }
        Node node=new Node(val);
        if(parent.val<val){
            parent.right=node;
        }else{
            parent.left=node;
        }
        return true;
    }

    public void remove(int val){
        Node parent=null;
        Node cur=root;
        while(cur!=null){
            if(cur.val<val){
                parent=cur;
                cur=cur.right;
            }else if(cur.val==val){
                removeNode(parent, cur);
                break;
            }else{
                parent=cur;
                cur=cur.left;
            }
        }
    }
    public void removeNode(Node parent,Node cur){
        if(cur.left==null){
            if(cur==root){
                cur=cur.right;
            }else if(cur==parent.left){
                parent.left=cur.right;
            }else{
                parent.right=cur.right;
            }
        }else if(cur.right==null){
            if(cur==root){
                cur=cur.left;
            }else if(cur==parent.left){
                parent.left=cur.left;
            }else{
                parent.right=cur.left;
            }
        }else{
            Node targetParent=cur;
            Node target=cur.right;
            while(target.left!=null){
                targetParent=target;
                target=targetParent.left;
            }
            cur.val=target.val;
            if(target==targetParent.left){
                targetParent.left=target.right;
            }else{
                targetParent.right=target.right;
            }
        }
    }
    public void inOrder(Node root){
        if(root==null){
            return;
        }
        inOrder(root.left);
        System.out.print(root.val+" ");
        inOrder(root.right);
    }

    public static void main(String[] args) {
        BInarysearchTree bInarysearchTree=new BInarysearchTree();
        int[]array={3,44,2,34,21,12,1};
        for (int i = 0; i < array.length; i++) {
            bInarysearchTree.insert(array[i]);
        }
        bInarysearchTree.inOrder(bInarysearchTree.root);
        System.out.println();
        System.out.println(bInarysearchTree.insert(3));
        bInarysearchTree.remove(1);
        bInarysearchTree.inOrder(bInarysearchTree.root);
    }
}*/
